/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Core;

import Slave.SlaveInfo;

/**
 *
 * @author Mr Bao
 */
public class MessageBuilder {

    public static final String ONE = ":";
    public static final String TWO = ";";
    public static final String NULL = "NULL";
    public static final String NOT_NULL = "NOT_NULL";

    public static String BuildLogInMessage(String username, String password) {
        String message = MessageType.Login + ONE + username + TWO + password;
        return message;
    }

    public static String BuildLogInMessage(String username, String password, boolean invisible) {
        String message = MessageType.Login + ONE + username + TWO + password + TWO + invisible;
        return message;
    }

    public static String BuildSendText(String to, String message) {
        return MessageType.SendText + ONE + to + TWO + message;
    }

    public static String BuildSendBuzz(String to) {
        return MessageType.SendBuzz + ONE + to;
    }

    public static String BuildChangeStatus(String newStatus, boolean showBusyIcon) {
        return MessageType.SendBuzz + ONE + newStatus + TWO + showBusyIcon;
    }

    public static String BuildInvisible(boolean invisible) {
        return MessageType.SendBuzz + ONE + invisible;
    }

    public static String BuildLogInResult(boolean error, long userId) {
        if (!error) {
            return MessageType.SendBuzz + ONE + NULL + TWO + userId;
        } else {
            return MessageType.LogInResult + ONE + NOT_NULL;
        }
    }

    public static String BuildRerportMessage(int slaveId, String slaveAddress, int slavePort, long currentConnections) {

        return MessageType.SlaveReportMessage + ONE + slaveId + TWO + slaveAddress + TWO + slavePort + TWO + currentConnections;
    }

    public static String BuildRerportMessage(SlaveInfo info) {
        return BuildRerportMessage(info.getId(), info.getAddress(), info.getPort(), info.getCurrentConnections());
    }

    public static String BuildGetSlaveMessage() {
        return MessageType.GetSlaveMessage;
    }

    public static String BuildGetSlaveResultMessage(SlaveInfo info) {
        return MessageType.GetSlaveResultMessage + ONE + info.getId() + TWO + info.getAddress() + TWO + info.getPort();
    }

    public static String BuildLogoutMessage(long userId) {
        return MessageType.LogOut + ONE + userId;
    }

    public static String BuildFriendReplyMessage(String from, String to, String message) {

        String returnMessage = MessageType.FriendReplyMessage;
        returnMessage += MessageBuilder.ONE;
        returnMessage += from;
        returnMessage += MessageBuilder.TWO;
        returnMessage += to;
        returnMessage += MessageBuilder.TWO;
        returnMessage += message;

        return returnMessage;
    }

    public static String BuildHaveGotSlaveMessage() {
        return MessageType.HaveGotSlaveMessage;
    }
}
